package com.sgmw.sales.tool.kong.sign.demo;

import java.util.LinkedHashMap;
import java.util.List;

import com.sgmw.sales.tool.kong.sign.AuthroizationGenerator;
import com.sgmw.sales.tool.kong.sign.generator.DefaultAuthroizationGenerator;
import com.sgmw.sales.tool.kong.sign.generator.SimpleAuthroizationGenerator;
import com.sgmw.sales.tool.kong.sign.headers.RequestHeader;
import com.sgmw.sales.tool.kong.sign.request.GetHttpRequest;
import com.sgmw.sales.tool.kong.sign.request.HttpRequest;
import com.sgmw.sales.tool.kong.sign.request.PostHttpRequest;
import com.sgmw.sales.tool.kong.sign.request.body.RequestBody;
import com.sgmw.sales.tool.kong.sign.request.body.RequestBodyForm;
import com.sgmw.sales.tool.kong.sign.request.body.RequestBodyJSON;

public class Test {
	public static void main(String[] args) {
//		testGetWithOutParam();
//		System.out.println("---------------------------------------------");
		testGetWithParam();
		System.out.println("---------------------------------------------");
		
		
//		testPostWithOutParamWithOutRequestBodyJSON();
//		System.out.println("---------------------------------------------");
//		testPostWithOutParamWithRequestBodyJSON();
//		System.out.println("---------------------------------------------");
		
//		testPostWithParamWithOutRequestBodyJSON();
//		System.out.println("---------------------------------------------");
//		testPostWithParamWithRequestBodyJSON();
//		System.out.println("---------------------------------------------");
//		
//		testPostWithOutParamWithRequestBodyForm();
//		System.out.println("---------------------------------------------");
//		testPostWithParamWithRequestBodyForm();
	}

	//1
	private static void testGetWithOutParam() {
		HttpRequest request = new GetHttpRequest("/outer/mallif/api/sample/test2", null);
		DefaultAuthroizationGenerator dag = new DefaultAuthroizationGenerator("test1234","test1234",request);
		List<RequestHeader> ret = dag.genAuthroziationHeaders();
		for(RequestHeader s : ret) {
			System.out.println(s);
		}
	}
	
	//2
	private static void testGetWithParam() {
		LinkedHashMap<String, String> queryParamMap = new LinkedHashMap<String,String>();
		queryParamMap.put("currentPage", "1");
		queryParamMap.put("pageSize", "10");
//		queryParamMap.put("a1", "1");
		HttpRequest request = new GetHttpRequest("/outer/mallif/api/carcertificate/samplequery", queryParamMap);
		DefaultAuthroizationGenerator dag = new DefaultAuthroizationGenerator("test1234","test1234",request);
		List<RequestHeader> ret = dag.genAuthroziationHeaders();
		for(RequestHeader s : ret) {
			System.out.println(s);
		}
	}
	
	//3
	private static void testPostWithOutParamWithOutRequestBodyJSON() {
		RequestBody requestBody = null;
		LinkedHashMap<String, String> queryParamMap = null;
		HttpRequest request = new PostHttpRequest("/outer/mallif/api/sample/test4", queryParamMap, requestBody);
		DefaultAuthroizationGenerator dag = new DefaultAuthroizationGenerator("test1234","test1234",request);
		List<RequestHeader> ret = dag.genAuthroziationHeaders();
		for(RequestHeader s : ret) {
			System.out.println(s);
		}
	}
	
	//4
	private static void testPostWithOutParamWithRequestBodyJSON() {
		RequestBody requestBody = new RequestBodyJSON("{'a':1,'b':'ssss'}") ;
		LinkedHashMap<String, String> queryParamMap = null;
		HttpRequest request = new PostHttpRequest("/outer/mallif/api/sample/test3", queryParamMap, requestBody);
		DefaultAuthroizationGenerator dag = new DefaultAuthroizationGenerator("test1234","test1234",request);
		List<RequestHeader> ret = dag.genAuthroziationHeaders();
		for(RequestHeader s : ret) {
			System.out.println(s);
		}
	}
	
	//5
	private static void testPostWithParamWithOutRequestBodyJSON() {
		RequestBody requestBody = null ;
		LinkedHashMap<String, String> queryParamMap = new LinkedHashMap<String,String>();
		queryParamMap.put("a", "1");
		queryParamMap.put("b", "2");
		HttpRequest request = new PostHttpRequest("/outer/mallif/api/sample/test4", queryParamMap, requestBody);
		DefaultAuthroizationGenerator dag = new DefaultAuthroizationGenerator("test1234","test1234",request);
		List<RequestHeader> ret = dag.genAuthroziationHeaders();
		for(RequestHeader s : ret) {
			System.out.println(s);
		}
	}
	
	//6
	private static void testPostWithParamWithRequestBodyJSON() {
		RequestBody requestBody = new RequestBodyJSON("{'a':1,'b':'ssss'}") ;
		LinkedHashMap<String, String> queryParamMap = new LinkedHashMap<String,String>();
		queryParamMap.put("a", "1");
		queryParamMap.put("b", "2");
		HttpRequest request = new PostHttpRequest("/outer/mallif/api/sample/test3", queryParamMap, requestBody);
		AuthroizationGenerator dag = new DefaultAuthroizationGenerator("test1234","test1234",request);
//		dag = new SimpleAuthroizationGenerator("test1234","test1234",request);
		List<RequestHeader> ret = dag.genAuthroziationHeaders();
		for(RequestHeader s : ret) {
			System.out.println(s);
		}
	}
	
	/**
	 * -----------------------------------------------------------------------------------------------------------------------------------------------
	 */
	
	//7
	private static void testPostWithOutParamWithRequestBodyForm() {
		LinkedHashMap<String, String> queryParamMap = null;
		
		LinkedHashMap<String, String> params = new LinkedHashMap<String,String>();
		params.put("a", "1");
		params.put("b", "2"); 
		RequestBody requestBody = new RequestBodyForm(params);
		
		HttpRequest request = new PostHttpRequest("/outer/mallif/api/sample/test4", queryParamMap, requestBody);
		DefaultAuthroizationGenerator dag = new DefaultAuthroizationGenerator("test1234","test1234",request);
		List<RequestHeader> ret = dag.genAuthroziationHeaders();
		for(RequestHeader s : ret) {
			System.out.println(s);
		}
	}
	
	//8
	private static void testPostWithParamWithRequestBodyForm() {
		LinkedHashMap<String, String> queryParamMap = new LinkedHashMap<String,String>();
		queryParamMap.put("a", "1");
		queryParamMap.put("b", "2");
		
		LinkedHashMap<String, String> params = new LinkedHashMap<String,String>();
		params.put("c", "3");
		params.put("d", "4"); 
		RequestBody requestBody = new RequestBodyForm(params);
		
		HttpRequest request = new PostHttpRequest("/outer/mallif/api/sample/test4", queryParamMap, requestBody);
		DefaultAuthroizationGenerator dag = new DefaultAuthroizationGenerator("test1234","test1234",request);
		List<RequestHeader> ret = dag.genAuthroziationHeaders();
		for(RequestHeader s : ret) {
			System.out.println(s);
		}
	}
}
